package org.agile2soft.nexoma.tapestry.model;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import org.apache.tapestry5.OptionGroupModel;
import org.apache.tapestry5.OptionModel;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.util.AbstractSelectModel;

public class LocaleSelectModel extends AbstractSelectModel {

    private String locales;
    
    final Messages messages;
    
    public LocaleSelectModel ( String locales , Messages messages) {
        this.locales = locales;
        this.messages = messages;
    }

    public List<OptionGroupModel> getOptionGroups() {
        return null;
    }

    public List<OptionModel> getOptions() {
        if ( locales!=null ) {
            List<OptionModel> localeList = new ArrayList<OptionModel>();
            String [] localeCodes = locales.split(",");
            for ( String localeCode : localeCodes ) {
                localeList.add(new LocaleOptionModel(new Locale(localeCode),messages.get(localeCode)));
            }
            return localeList;
        }
        return null;
    }

}